package com.zqx.util;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;


import com.zqx.pojo.Laoshi;
import com.zqx.pojo.Laoxue;
import com.zqx.pojo.Stu;

public class Test {
public static void main(String[] args) {
	SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();
	Session session = sf.openSession();
	Transaction tx = session.beginTransaction();
//	Query query = session.createQuery("from Laoxue l where l.stu.sph = '222zqx'");
//	List<Laoxue> laoxues =query.list();
//	Laoxue laoxue = laoxues.get(0);
//	System.out.println(laoxue.getStu().getSname());
	
	Laoxue laoxue =new Laoxue();
	Laoshi laoshi = new Laoshi();
	Stu stu = new Stu();
	laoshi.setLname("zhu");
	laoshi.setLage(35);
	laoxue.setLaoshi(laoshi);
	stu.setSage(19);
	stu.setSname("liu");
	stu.setSph("6548");
	laoxue.setStu(stu);
	session.save(laoxue);
	tx.commit();
	
}
}
